﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Cid
{
	public class DecoratedObject : IDecoratedObject
	{
		private Dictionary<string, object> properties;

		private Dictionary<string, object> Properties
		{
			get {
				if (this.properties == null)
					this.properties = new Dictionary<string, object>();
				return this.properties;
			}
		}

		public void Each(Action<KeyValuePair<string, object>> action) 
		{
			foreach (KeyValuePair<string, object> pair in Properties)
				action(pair);
		}

		public object this[string propertyName]
		{
			get { return this.GetProperty(propertyName); }
			set { this.SetProperty(propertyName, value); }
		}

		protected virtual object GetProperty(string propertyName)
		{
			if (this.Properties.ContainsKey(propertyName))
				return this.Properties[propertyName];
			return null;
		}

		protected virtual void SetProperty(string propertyName, object value)
		{
			this.Properties[propertyName] = value;
		}

	}
}
